import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
import { HydratedDocument } from 'mongoose'
import * as mongoose from 'mongoose'
import { Subject } from './subject.schema'

export type TestPaperDocument = HydratedDocument<TestPaper>

@Schema()
export class TestPaper {
  @Prop({
    required: true,
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Subject'
  })
  subject: Subject

  @Prop({
    default: [],
    type: [
      {
        optionText: { type: String },
        optionType: { type: Number },
        optionImage: { type: String },
        isCorrect: { type: Boolean }
      }
    ]
  })
  randomOptions: {
    optionText: string
    optionType: number
    optionImage: string
    isCorrect: boolean
  }[]

  @Prop({ default: '', type: String })
  answer: string

  @Prop({ default: false, type: Boolean })
  isItCorrect: boolean
}

export const TestPaperSchema = SchemaFactory.createForClass(TestPaper)
